﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace myPhoneBook
{
    public partial class FormAdd : Form
    {
        DataSetMyPhoneBook ds;
        DataSetMyPhoneBookTableAdapters.ContactsTableAdapter contact_adt = new DataSetMyPhoneBookTableAdapters.ContactsTableAdapter();
        DataSetMyPhoneBookTableAdapters.HistoriesTableAdapter history_adt = new DataSetMyPhoneBookTableAdapters.HistoriesTableAdapter();

        public FormAdd()
        {
            InitializeComponent();
        }

        public FormAdd(DataSetMyPhoneBook ds, DataSetMyPhoneBookTableAdapters.ContactsTableAdapter contact_adt,
                                           DataSetMyPhoneBookTableAdapters.HistoriesTableAdapter history_adt)
        {
            InitializeComponent();
            this.ds = ds;
            this.contact_adt = contact_adt;
            this.history_adt = history_adt;
        }

        private void bntAdd2_Click(object sender, EventArgs e)
        {
            string strContactName, strPhoneNumber, strEmail, strAddress, strOrganization,
                strNickName, strWebsite, strNotes;
            DateTime dtBirthday;

            strContactName  = txtContactName.Text;
            strPhoneNumber  = txtPhoneNumber.Text;
            strEmail = txtEmail.Text;
            strAddress = txtAddress.Text;
            strOrganization = txtOrgan.Text;
            strNickName = txtNickname.Text;
            strWebsite = txtWebsite.Text;
            strNotes = txtNotes.Text;
            //thieeu cai AVATAR

            dtBirthday = dtpkBirthday.Value;

            //add
            ds.Contacts.AddContactsRow(strContactName, strPhoneNumber, strEmail, dtBirthday, strAddress,
                strOrganization, strNickName, "link5", strWebsite, strNotes);
            
            //update into Database
            contact_adt.Update(ds.Contacts);
            //Fill data from Database to Dataset AGAIN
            contact_adt.Fill(ds.Contacts);

            //Close formAdd
            this.Close();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Title = "Choose your avatar";
            dlg.Multiselect = false;
            dlg.Filter = "Image Files|*.jpg;*.gif;*.bmp;*.png;*.jpeg";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                txtAvatarLink.Text = dlg.FileName;
            }
        }
    }
}
